#include "UIUtils.h"
#include <mutex>
#include <thread>
#include <QMainWindow>


namespace
{
Message::TrayMessage *pTrayMsg = nullptr;
QMainWindow *pMainWnd = nullptr;

}

namespace Message
{
TrayMessage::TrayMessage(QObject *obj) : QObject(obj) {}
TrayMessage *TrayMessage::Ins()
{
    static std::mutex mut;
    std::unique_lock<std::mutex> lock(mut);
    if (!pTrayMsg)
        pTrayMsg = new TrayMessage;
    return pTrayMsg;
}
void TrayMessage::registTray(QSystemTrayIcon *tray)
{
    if (!tray) return;
    void(QSystemTrayIcon:: * trayMsge)(const QString &, const QString &,
                                       const QIcon &, int) = &QSystemTrayIcon::showMessage;
    QObject::connect(this, &TrayMessage::trayMsg, tray, trayMsge);
}
void TrayMessage::registMainWindow(QMainWindow *mainWnd)
{
    pMainWnd = mainWnd;
}
QMainWindow *TrayMessage::mainWndPointer()
{
    return pMainWnd;
}
void TrayMessage::showMsg(const QString &title, const QString &msg,
                          const QIcon &icon, int msecs)
{
    emit trayMsg(title, msg, icon, msecs);
}
void TrayMessage::startTaskbarProgressFunc(int minVal, int maxVal)
{
    emit startTaskBarProgress(minVal, maxVal);
}
void TrayMessage::setTaskBarProgressValueFunc(int val)
{
    emit setTaskBarProgressValue(val);
}
}
